home *** CD-ROM | disk | FTP | other *** search
/ Champak Vol C-14 / Vol C-14.iso / games / snackes.swf / scripts / FRadioButtonSymbol.as < prev    next >
Text File  |  2012-04-23  |  17KB  |  620 lines

  1. function FRadioButtonClass()
  2. {
  3.    this.init();
  4. }
  5. function FRadioButtonGroupClass()
  6. {
  7.    this.radioInstances = new Array();
  8. }
  9. FRadioButtonClass.prototype = new FUIComponentClass();
  10. FRadioButtonGroupClass.prototype = new FUIComponentClass();
  11. Object.registerClass("FRadioButtonSymbol",FRadioButtonClass);
  12. FRadioButtonClass.prototype.init = function()
  13. {
  14.    if(this.initialState == undefined)
  15.    {
  16.       this.selected = false;
  17.    }
  18.    else
  19.    {
  20.       this.selected = this.initialState;
  21.    }
  22.    super.setSize(this._width,this._height);
  23.    this.boundingBox_mc.unloadMovie();
  24.    this.boundingBox_mc._width = 0;
  25.    this.boundingBox_mc._height = 0;
  26.    this.attachMovie("frb_hitArea","frb_hitArea_mc",1);
  27.    this.attachMovie("frb_states","frb_states_mc",2);
  28.    this.attachMovie("FLabelSymbol","fLabel_mc",3);
  29.    super.init();
  30.    this._xscale = 100;
  31.    this._yscale = 100;
  32.    this.setSize(this.width,this.height);
  33.    this.setChangeHandler(this.changeHandler);
  34.    if(this.label != undefined)
  35.    {
  36.       this.setLabel(this.label);
  37.    }
  38.    if(this.initialState == undefined)
  39.    {
  40.       this.setValue(false);
  41.    }
  42.    else
  43.    {
  44.       this.setValue(this.initialState);
  45.    }
  46.    if(this.data == "")
  47.    {
  48.       this.data = undefined;
  49.    }
  50.    else
  51.    {
  52.       this.setData(this.data);
  53.    }
  54.    this.addToRadioGroup();
  55.    this.ROLE_SYSTEM_RADIOBUTTON = 45;
  56.    this.STATE_SYSTEM_SELECTED = 16;
  57.    this.EVENT_OBJECT_STATECHANGE = 32778;
  58.    this.EVENT_OBJECT_NAMECHANGE = 32780;
  59.    this._accImpl.master = this;
  60.    this._accImpl.stub = false;
  61.    this._accImpl.get_accRole = this.get_accRole;
  62.    this._accImpl.get_accName = this.get_accName;
  63.    this._accImpl.get_accState = this.get_accState;
  64.    this._accImpl.get_accDefaultAction = this.get_accDefaultAction;
  65.    this._accImpl.accDoDefaultAction = this.accDoDefaultAction;
  66. };
  67. FRadioButtonClass.prototype.setHitArea = function(w, h)
  68. {
  69.    var hit = this.frb_hitArea_mc;
  70.    this.hitArea = hit;
  71.    if(this.frb_states_mc._width > w)
  72.    {
  73.       hit._width = this.frb_states_mc._width;
  74.    }
  75.    else
  76.    {
  77.       hit._width = w;
  78.    }
  79.    hit._visible = false;
  80.    if(arguments.length > 1)
  81.    {
  82.       hit._height = h;
  83.    }
  84. };
  85. FRadioButtonClass.prototype.txtFormat = function(pos)
  86. {
  87.    var txtS = this.textStyle;
  88.    var sTbl = this.styleTable;
  89.    txtS.align = sTbl.textAlign.value != undefined ? undefined : (txtS.align = pos);
  90.    txtS.leftMargin = sTbl.textLeftMargin.value != undefined ? undefined : (txtS.leftMargin = 0);
  91.    txtS.rightMargin = sTbl.textRightMargin.value != undefined ? undefined : (txtS.rightMargin = 0);
  92.    if(this.flabel_mc._height > this.height)
  93.    {
  94.       super.setSize(this.width,this.flabel_mc._height);
  95.    }
  96.    else
  97.    {
  98.       super.setSize(this.width,this.height);
  99.    }
  100.    this.setEnabled(this.enable);
  101. };
  102. FRadioButtonClass.prototype.setSize = function(w, h)
  103. {
  104.    this.setLabel(this.getLabel());
  105.    this.setLabelPlacement(this.labelPlacement);
  106.    if(this.frb_states_mc._height < this.flabel_mc.labelField._height)
  107.    {
  108.       super.setSize(w,this.flabel_mc.labelField._height);
  109.    }
  110.    this.setHitArea(this.width,this.height);
  111.    this.setLabelPlacement(this.labelPlacement);
  112. };
  113. FRadioButtonClass.prototype.setLabelPlacement = function(pos)
  114. {
  115.    this.setLabel(this.getLabel());
  116.    this.txtFormat(pos);
  117.    var halfLabelH = this.fLabel_mc._height / 2;
  118.    var halfFrameH = this.frb_states_mc._height / 2;
  119.    var vertCenter = halfFrameH - halfLabelH;
  120.    var radioWidth = this.frb_states_mc._width;
  121.    var frame = this.frb_states_mc;
  122.    var label = this.fLabel_mc;
  123.    var w = this.width - frame._width;
  124.    if(frame._width > this.width)
  125.    {
  126.       w = 0;
  127.    }
  128.    else
  129.    {
  130.       w = this.width - frame._width;
  131.    }
  132.    this.fLabel_mc.setSize(w);
  133.    if(pos == "right" || pos == undefined)
  134.    {
  135.       this.labelPlacement = "right";
  136.       this.frb_states_mc._x = 0;
  137.       this.fLabel_mc._x = radioWidth;
  138.       this.txtFormat("left");
  139.    }
  140.    else if(pos == "left")
  141.    {
  142.       this.labelPlacement = "left";
  143.       this.fLabel_mc._x = 0;
  144.       this.frb_states_mc._x = this.width - radioWidth;
  145.       this.txtFormat("right");
  146.    }
  147.    this.fLabel_mc._y = vertCenter;
  148.    this.frb_hitArea_mc._y = vertCenter;
  149.    this.setLabel(this.getLabel());
  150. };
  151. FRadioButtonClass.prototype.setData = function(dataValue)
  152. {
  153.    this.data = dataValue;
  154. };
  155. FRadioButtonClass.prototype.getData = function()
  156. {
  157.    return this.data;
  158. };
  159. FRadioButtonClass.prototype.getState = function()
  160. {
  161.    return this.selected;
  162. };
  163. FRadioButtonClass.prototype.getSize = function()
  164. {
  165.    return this.width;
  166. };
  167. FRadioButtonClass.prototype.getGroupName = function()
  168. {
  169.    return this.groupName;
  170. };
  171. FRadioButtonClass.prototype.setGroupName = function(groupName)
  172. {
  173.    var i = 0;
  174.    while(i < this._parent[this.groupName].radioInstances.length)
  175.    {
  176.       if(this._parent[this.groupName].radioInstances[i] == this)
  177.       {
  178.          delete this._parent[this.groupName].radioInstances[i];
  179.       }
  180.       i++;
  181.    }
  182.    this.groupName = groupName;
  183.    this.addToRadioGroup();
  184. };
  185. FRadioButtonClass.prototype.addToRadioGroup = function()
  186. {
  187.    if(this._parent[this.groupName] == undefined)
  188.    {
  189.       this._parent[this.groupName] = new FRadioButtonGroupClass();
  190.    }
  191.    this._parent[this.groupName].addRadioInstance(this);
  192. };
  193. FRadioButtonClass.prototype.setValue = function(selected)
  194. {
  195.    if(selected || selected == undefined)
  196.    {
  197.       this.setState(true);
  198.       this.focusRect.removeMovieClip();
  199.       this.executeCallBack();
  200.    }
  201.    else if(selected == false)
  202.    {
  203.       this.setState(false);
  204.    }
  205. };
  206. FRadioButtonClass.prototype.setTabState = function(selected)
  207. {
  208.    Selection.setFocus(this);
  209.    this.setState(selected);
  210.    this.drawFocusRect();
  211.    this.executeCallBack();
  212. };
  213. FRadioButtonClass.prototype.setState = function(selected)
  214. {
  215.    if(selected || selected == undefined)
  216.    {
  217.       this.tabEnabled = true;
  218.       for(var i in this._parent)
  219.       {
  220.          if(this != this._parent[i] && this._parent[i].groupName == this.groupName)
  221.          {
  222.             this._parent[i].setState(false);
  223.             this._parent[i].tabEnabled = false;
  224.          }
  225.       }
  226.    }
  227.    if(this.enable)
  228.    {
  229.       this.flabel_mc.setEnabled(true);
  230.       if(selected || selected == undefined)
  231.       {
  232.          this.frb_states_mc.gotoAndStop("selectedEnabled");
  233.          this.enabled = false;
  234.          this.selected = true;
  235.          this.tabEnabled = true;
  236.          this.tabFocused = true;
  237.       }
  238.       else
  239.       {
  240.          this.frb_states_mc.gotoAndStop("unselectedEnabled");
  241.          this.enabled = true;
  242.          this.selected = false;
  243.          this.tabEnabled = false;
  244.          var enabTrue = this._parent[this.groupName].getEnabled();
  245.          var noneSelect = this._parent[this.groupName].getValue() == undefined;
  246.          if(enabTrue && noneSelect)
  247.          {
  248.             this._parent[this.groupName].radioInstances[0].tabEnabled = true;
  249.          }
  250.       }
  251.    }
  252.    else
  253.    {
  254.       this.flabel_mc.setEnabled(false);
  255.       if(selected || selected == undefined)
  256.       {
  257.          this.frb_states_mc.gotoAndStop("selectedDisabled");
  258.          this.enabled = false;
  259.          this.selected = true;
  260.          this.tabEnabled = false;
  261.       }
  262.       else
  263.       {
  264.          this.frb_states_mc.gotoAndStop("unselectedDisabled");
  265.          this.enabled = false;
  266.          this.selected = false;
  267.          this.tabEnabled = false;
  268.       }
  269.    }
  270.    if(Accessibility.isActive())
  271.    {
  272.       Accessibility.sendEvent(this,0,this.EVENT_OBJECT_STATECHANGE,true);
  273.    }
  274. };
  275. FRadioButtonClass.prototype.getValue = function()
  276. {
  277.    if(this.selected)
  278.    {
  279.       if(this.data == "" || this.data == undefined)
  280.       {
  281.          return this.getLabel();
  282.       }
  283.       return this.data;
  284.    }
  285. };
  286. FRadioButtonClass.prototype.setEnabled = function(enable)
  287. {
  288.    if(enable == true || enable == undefined)
  289.    {
  290.       this.enable = true;
  291.       super.setEnabled(true);
  292.    }
  293.    else
  294.    {
  295.       this.enable = false;
  296.       super.setEnabled(false);
  297.    }
  298.    this.setState(this.selected);
  299.    var cgn = this._parent[this.groupName].getEnabled() == undefined;
  300.    var cgnez = this._parent[this.groupName].radioInstances[0].getEnabled() == false;
  301.    if(cgn && cgnez)
  302.    {
  303.       var i = 0;
  304.       while(i < this._parent[this.groupName].radioInstances.length)
  305.       {
  306.          if(this._parent[this.groupName].radioInstances[i].getEnabled() == true)
  307.          {
  308.             this._parent[this.groupName].radioInstances[i].tabEnabled = true;
  309.             return undefined;
  310.          }
  311.          i++;
  312.       }
  313.    }
  314. };
  315. FRadioButtonClass.prototype.getEnabled = function()
  316. {
  317.    return this.enable;
  318. };
  319. FRadioButtonClass.prototype.setLabel = function(label)
  320. {
  321.    this.fLabel_mc.setLabel(label);
  322.    this.txtFormat();
  323.    if(Accessibility.isActive())
  324.    {
  325.       Accessibility.sendEvent(this,0,this.EVENT_OBJECT_NAMECHANGE);
  326.    }
  327. };
  328. FRadioButtonClass.prototype.getLabel = function()
  329. {
  330.    return this.fLabel_mc.getLabel();
  331. };
  332. FRadioButtonClass.prototype.onPress = function()
  333. {
  334.    this.pressFocus();
  335.    this.frb_states_mc.gotoAndStop("press");
  336. };
  337. FRadioButtonClass.prototype.onRelease = function()
  338. {
  339.    this.frb_states_mc.gotoAndStop("unselectedDisabled");
  340.    this.setValue(!this.selected);
  341. };
  342. FRadioButtonClass.prototype.onReleaseOutside = function()
  343. {
  344.    this.frb_states_mc.gotoAndStop("unselectedEnabled");
  345. };
  346. FRadioButtonClass.prototype.onDragOut = function()
  347. {
  348.    this.frb_states_mc.gotoAndStop("unselectedEnabled");
  349. };
  350. FRadioButtonClass.prototype.onDragOver = function()
  351. {
  352.    this.frb_states_mc.gotoAndStop("press");
  353. };
  354. FRadioButtonClass.prototype.executeCallBack = function()
  355. {
  356.    this.handlerObj[this.changeHandler](this._parent[this.groupName]);
  357. };
  358. FRadioButtonGroupClass.prototype.addRadioInstance = function(instance)
  359. {
  360.    this.radioInstances.push(instance);
  361.    this.radioInstances[0].tabEnabled = true;
  362. };
  363. FRadioButtonGroupClass.prototype.setEnabled = function(enableFlag)
  364. {
  365.    var i = 0;
  366.    while(i < this.radioInstances.length)
  367.    {
  368.       this.radioInstances[i].setEnabled(enableFlag);
  369.       i++;
  370.    }
  371. };
  372. FRadioButtonGroupClass.prototype.getEnabled = function()
  373. {
  374.    var i = 0;
  375.    while(i < this.radioInstances.length)
  376.    {
  377.       if(this.radioInstances[i].getEnabled() != this.radioInstances[0].getEnabled())
  378.       {
  379.          return undefined;
  380.       }
  381.       i++;
  382.    }
  383.    return this.radioInstances[0].getEnabled();
  384. };
  385. FRadioButtonGroupClass.prototype.setChangeHandler = function(changeHandler, obj)
  386. {
  387.    var i = 0;
  388.    while(i < this.radioInstances.length)
  389.    {
  390.       this.radioInstances[i].setChangeHandler(changeHandler,obj);
  391.       i++;
  392.    }
  393. };
  394. FRadioButtonGroupClass.prototype.getValue = function()
  395. {
  396.    var i = 0;
  397.    while(i < this.radioInstances.length)
  398.    {
  399.       if(this.radioInstances[i].selected == true)
  400.       {
  401.          if(this.radioInstances[i].data == "" || this.radioInstances[i].data == undefined)
  402.          {
  403.             return this.radioInstances[i].getLabel();
  404.          }
  405.          return this.radioInstances[i].data;
  406.       }
  407.       i++;
  408.    }
  409. };
  410. FRadioButtonGroupClass.prototype.getData = function()
  411. {
  412.    var i = 0;
  413.    while(i < this.radioInstances.length)
  414.    {
  415.       if(this.radioInstances[i].selected)
  416.       {
  417.          return this.radioInstances[i].getData();
  418.       }
  419.       i++;
  420.    }
  421. };
  422. FRadioButtonGroupClass.prototype.getInstance = function()
  423. {
  424.    var i = 0;
  425.    while(i < this.radioInstances.length)
  426.    {
  427.       if(this.radioInstances[i].selected == true)
  428.       {
  429.          return i;
  430.       }
  431.       undefined;
  432.       i++;
  433.    }
  434. };
  435. FRadioButtonGroupClass.prototype.setValue = function(dataValue)
  436. {
  437.    var i = 0;
  438.    while(i < this.radioInstances.length)
  439.    {
  440.       if(this.radioInstances[i].data == dataValue)
  441.       {
  442.          this.radioInstances[i].setValue(true);
  443.          return undefined;
  444.       }
  445.       i++;
  446.    }
  447.    var i = 0;
  448.    while(i < this.radioInstances.length)
  449.    {
  450.       if(this.radioInstances[i].getLabel() == dataValue)
  451.       {
  452.          this.radioInstances[i].setValue(true);
  453.       }
  454.       i++;
  455.    }
  456. };
  457. FRadioButtonGroupClass.prototype.setSize = function(w)
  458. {
  459.    var i = 0;
  460.    while(i < this.radioInstances.length)
  461.    {
  462.       this.radioInstances[i].setSize(w);
  463.       i++;
  464.    }
  465. };
  466. FRadioButtonGroupClass.prototype.getSize = function()
  467. {
  468.    var widestRadio = 0;
  469.    var i = 0;
  470.    while(i < this.radioInstances.length)
  471.    {
  472.       if(this.radioInstances[i].width >= widestRadio)
  473.       {
  474.          widestRadio = this.radioInstances[i].width;
  475.       }
  476.       i++;
  477.    }
  478.    return widestRadio;
  479. };
  480. FRadioButtonGroupClass.prototype.setGroupName = function(groupName)
  481. {
  482.    this.oldGroupName = this.radioInstances[0].groupName;
  483.    var i = 0;
  484.    while(i < this.radioInstances.length)
  485.    {
  486.       this.radioInstances[i].groupName = groupName;
  487.       this.radioInstances[i].addToRadioGroup();
  488.       i++;
  489.    }
  490.    delete this._parent[this.oldGroupName];
  491. };
  492. FRadioButtonGroupClass.prototype.getGroupName = function()
  493. {
  494.    return this.radioInstances[0].groupName;
  495. };
  496. FRadioButtonGroupClass.prototype.setLabelPlacement = function(pos)
  497. {
  498.    var i = 0;
  499.    while(i < this.radioInstances.length)
  500.    {
  501.       this.radioInstances[i].setLabelPlacement(pos);
  502.       i++;
  503.    }
  504. };
  505. FRadioButtonGroupClass.prototype.setStyleProperty = function(propName, value, isGlobal)
  506. {
  507.    var i = 0;
  508.    while(i < this.radioInstances.length)
  509.    {
  510.       this.radioInstances[i].setStyleProperty(propName,value,isGlobal);
  511.       i++;
  512.    }
  513. };
  514. FRadioButtonGroupClass.prototype.addListener = function()
  515. {
  516.    var i = 0;
  517.    while(i < this.radioInstances.length)
  518.    {
  519.       this.radioInstances[i].addListener();
  520.       i++;
  521.    }
  522. };
  523. FRadioButtonGroupClass.prototype.applyChanges = function()
  524. {
  525.    var i = 0;
  526.    while(i < this.radioInstances.length)
  527.    {
  528.       this.radioInstances[i].applyChanges();
  529.       i++;
  530.    }
  531. };
  532. FRadioButtonGroupClass.prototype.removeListener = function(component)
  533. {
  534.    var i = 0;
  535.    while(i < this.radioInstances.length)
  536.    {
  537.       this.radioInstances[i].removeListener(component);
  538.       i++;
  539.    }
  540. };
  541. FRadioButtonClass.prototype.drawFocusRect = function()
  542. {
  543.    this.drawRect(-2,-2,this._width + 6,this._height - 3);
  544. };
  545. FRadioButtonClass.prototype.myOnKillFocus = function()
  546. {
  547.    Key.removeListener(this.keyListener);
  548.    this.focused = false;
  549.    this.focusRect.removeMovieClip();
  550.    this._parent[this.groupName].foobar = 0;
  551. };
  552. FRadioButtonClass.prototype.myOnKeyDown = function()
  553. {
  554.    if(Key.getCode() == 32 && this._parent[this.groupName].getValue() == undefined)
  555.    {
  556.       if(this._parent[this.groupName].radioInstances[0] == this)
  557.       {
  558.          this.setTabState(true);
  559.       }
  560.    }
  561.    if(Key.getCode() == 40 && this.pressOnce == undefined)
  562.    {
  563.       this.foobar = this._parent[this.groupName].getInstance();
  564.       var i = this.foobar;
  565.       while(i < this._parent[this.groupName].radioInstances.length)
  566.       {
  567.          var inc = i + 1;
  568.          if(this._parent[this.groupName].radioInstances[inc].getEnabled())
  569.          {
  570.             this._parent[this.groupName].radioInstances[inc].setTabState(true);
  571.             return undefined;
  572.          }
  573.          i++;
  574.       }
  575.    }
  576.    if(Key.getCode() == 38 && this.pressOnce == undefined)
  577.    {
  578.       this.foobar = this._parent[this.groupName].getInstance();
  579.       var i = this.foobar;
  580.       while(i >= 0)
  581.       {
  582.          var inc = i - 1;
  583.          if(this._parent[this.groupName].radioInstances[inc].getEnabled())
  584.          {
  585.             this._parent[this.groupName].radioInstances[inc].setTabState(true);
  586.             return undefined;
  587.          }
  588.          i--;
  589.       }
  590.    }
  591. };
  592. FRadioButtonClass.prototype.get_accRole = function(childId)
  593. {
  594.    return this.master.ROLE_SYSTEM_RADIOBUTTON;
  595. };
  596. FRadioButtonClass.prototype.get_accName = function(childId)
  597. {
  598.    return this.master.getLabel();
  599. };
  600. FRadioButtonClass.prototype.get_accState = function(childId)
  601. {
  602.    if(this.master.getState())
  603.    {
  604.       return this.master.STATE_SYSTEM_SELECTED;
  605.    }
  606.    return 0;
  607. };
  608. FRadioButtonClass.prototype.get_accDefaultAction = function(childId)
  609. {
  610.    if(this.master.getState())
  611.    {
  612.       return "UnCheck";
  613.    }
  614.    return "Check";
  615. };
  616. FRadioButtonClass.prototype.accDoDefaultAction = function(childId)
  617. {
  618.    this.master.setValue(!this.master.getValue());
  619. };
  620.